*************************************************************************
************************Figure 3: Event Study****************************
*************************************************************************
grstyle init
grstyle set plain

cd $PATH

// outcome var: gini coefficient

* use matched sample

use incdistribution.dta, clear

merge m:1 commid using kernelmatch.dta, keep(match) nogen
merge 1:1 commid WAVE using so2_match_long.dta, keep(match) nogen 

g loggini=log(gini)	

tostring WAVE, replace

encode WAVE, g(yr)
destring WAVE, replace

g time=.
replace time=-3 if WAVE==1989
replace time=-2 if WAVE==1991
replace time=-1 if WAVE==1993
replace time= 0 if WAVE==1997
replace time= 1 if WAVE==2000
replace time= 2 if WAVE==2004
replace time= 3 if WAVE==2006
replace time= 4 if WAVE==2009
replace time= 5 if WAVE==2011
replace time= 6 if WAVE==2015

g time_to_treat=time if tcz==1

global score comm denc div econ health house market soc trans edc mart sani

eststo clear

xtset commid WAVE

* Graph is generated by eventdd (Clarke and Schythe, 2020)
* Damian Clarke & Kathya Tapia Schythe, 2020. 
* "EVENTDD: Stata module to panel event study models and generate event study plots," 
* Statistical Software Components S458737, Boston College Department of Economics, revised 01 Jan 2021. 

eventdd loggini $score i.WAVE, timevar(time_to_treat) level(95) method(fe, cluster(commid)) baseline(0) noline coef_op(msymbol(circle))   ///
graph_op( ytitle("Change relative to 1997", size(small) margin(small)) xtitle("") ylabel(, labsize(small))  ///
tlabel(-4 `" " " "Wave" "' -3 `" "-4" "1989" "' -2 `" "-3" "1991" "' -1 `" "-2" "1993" "' 0 `" "-1" "1997" "' 1 `" "1" "2000" "' 2 `" "2" "2004" "' 3 `" "3" "2006" "' 4 `" "4" "2009" "' 5 `" "5" "2011" "' 6 `" "6" "2015" "', labsize(small) ) scheme(s1mono) xlabel(-4(1)5) xline(0, lp(dash) lc(black) ) yline(0, lc(cranberry) )  ///
legend(order (2 "Estimated coefficient"  1 "95% CI") region(lwidth(none)))) 
 
graph export fig3_eventgini.eps, replace


